﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace CoolCode.Web.Mvc 
{
    public static  class HttpContextExtensions
    {
        /// <summary>
        /// Determines if the current request is an ajax request
        /// </summary>
        /// <param name="request">Instance of the HttpRequestBase for the request</param>
        /// <returns></returns>
        public static bool IsAjax(this HttpRequestBase request)
        {
            return (!string.IsNullOrEmpty(request.Headers["Ajax"]) ||
                "XMLHttpRequest".Equals(request.Headers["X-Requested-With"],
                StringComparison.InvariantCultureIgnoreCase));
        }
    }
}
